
#ifndef __COMMON_TYPES_H__
#define __COMMON_TYPES_H__

#pragma warning(disable: 4018 4267)

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>

#define _ ,

#ifndef NULL
#define NULL 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

typedef int             BOOL;
typedef unsigned char   BYTE;
typedef unsigned char   UCHAR;
typedef unsigned short  USHORT;
typedef unsigned int    UINT;
typedef unsigned short  WORD;
typedef short           INT16;
typedef signed char     INT8;
typedef unsigned long   DWORD;
typedef unsigned long   ULONG;
typedef unsigned __int64 UINT64;
typedef __int64         INT64;

#define FORCE_INLINE __inline

#define NewObj(TYPE) new TYPE

#define ZeroStruct(ptr) memset(ptr, 0, sizeof(*ptr))

#define SAFE_RELEASE(ptr) if (ptr != NULL) { ptr->Release(); ptr = NULL; }

#define ASSERT(CONDITION) if (CONDITION) ; else AssertionFailed(#CONDITION, __FILE__, __LINE__);

#define _IsState(VAR, STATE) ((VAR) & (STATE))
#define _SetStateYes(VAR, STATE) VAR |= (STATE)
#define _SetStateNo(VAR, STATE) VAR &= ~(STATE)
#define _SetState(VAR, STATE, OPT) if (OPT) { _SetStateYes(VAR, STATE); } else { _SetStateNo(VAR, STATE); }

#define CASSERT(COND) typedef char __AP_COMM_CASSERT [(COND) ? 1 : -1]
#define CASSERT_MSG(COND, MSG) typedef char __AP_COMM_CASSERT_##MSG [(COND) ? 1 : -1]

template <class T>
inline void New(T * ptr) { new (ptr) T(); }

template <class T, class A1>
inline void New(T * ptr, A1 & a1) { new (ptr) T(a1); }

template <class T>
inline void Delete(T *& var) { delete var; var = NULL; }

void AssertionFailed(const char * condition, const char * file, int line);

#endif // __COMMON_TYPES_H__